package logic

import (
	"context"
	"errors"
	"mooc_srv/models"

	"mooc_srv/internal/svc"
	"mooc_srv/mooc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddLogic {
	return &UserAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户创建
func (l *UserAddLogic) UserAdd(in *mooc.UserAddRequest) (*mooc.UserAddResponse, error) {
	// todo: add your logic here and delete this line

	var err error

	var u models.User
	u.Mobile = in.Mobile
	err = u.Create()
	if err != nil {
		logx.Error("用户创建失败")
		return nil, errors.New("用户创建失败")
	}

	return &mooc.UserAddResponse{
		UserId: int64(u.ID),
	}, nil
}
